package it.agm.fanta.adapter;

import it.agm.fanta.FantaserviceApp;
import it.agm.fanta.R;
import it.agm.fanta.asynctask.util.SyncUtility;
import it.agm.fanta.model.LegaSquadra;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RadioButton;

public class RadioLegaAdapter {

	public RadioButton getView(final Activity activity, final LegaSquadra lega) {
		LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View convertView = inflater.inflate(R.layout.drawer_radio_item, null);
		RadioButton button = (RadioButton) convertView
				.findViewById(R.id.radio_pirates);
		if (lega != null) {

			button.setText(lega.getNome());
			button.setId(Integer.parseInt("" + lega.getIdlega()));
			button.setBackgroundColor(activity.getResources().getColor(android.R.color.transparent));
			button.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					
					for(LegaSquadra lega : FantaserviceApp.leghe){
						
						if((""+v.getId()).equals(""+lega.getIdlega())){
							FantaserviceApp.request.setIdlega("" + v.getId());
							FantaserviceApp.request.setGiornataincorso(false);
							FantaserviceApp.lega = lega;
						}
					}
					SyncUtility.syncForLega();
				}
			});
		}

		return button;
	}

	
}
